<!-- 验证插件 -->
<script src="/static/plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="/static/plugins/jquery-validation/localization/messages_zh.min.js"></script>
<!-- 针对当前主题进行简单封装，精简代码 -->
<script src="/static/sdtheme/scripts/sdvalidate.js"></script>

<script>
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    $(function () {
       pageInit();
    });

    function pageInit(){
       $("#Used").selectpicker('val', '{{.m.Used}}');
       var url = '{{ urlfor "EquipmentSimCardsController.SelectPicker"}}';
       rms.selectSimNO(url, '{{.m.Sim_no}}', '{{.m.Used}}');

       var url2 = '{{ urlfor "EquipmentRoomController.SelectPicker"}}';
       rms.selectRoomNO(url2, '{{.m.Room_no}}', '{{.m.Used}}');

       //验证
       validateInfo();
    }

    //表单验证及AJAX提交
    function validateInfo() {
        var $thisForm = $('#thisForm');
        $thisForm.sdvalidate({
            rules: {
                DTU_no: {
                    maxlength: 12,
                    required: true
                },
                TimeInterval:{
                    min: 1,
                    required: true
                }
            },
            messages: {},
            submitHandler: function (form) {
				var url ='{{ urlfor "EquipmentDtuConfigController.Edit"}}';
				var params = $thisForm.serialize();

				$.sdpost(url, params, function(re){
					if(re.code === 0){
						parent.layer.msg(re.msg);
						parent.refresh(re.obj);
						parent.layer.close(index)
					}else{
						parent.layer.alert(re.msg,{icon:2,title:'失败'})
					}
				});
               return false;
            }
        });
    }

    function FormSubmit() {
        $("#thisForm").submit();		
    }
</script>